package com.sbs.session.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Author fyy
 * @Description session共享
 * @Date 2020/5/15 11:24
 */
@RestController
public class SessionController {

    private static Logger logger = LoggerFactory.getLogger(SessionController.class);

    @Value("${server.port}")
    private String port;

    /**
     * @Author fyy
     * @Description 共享session置值
     * @Date 2020/5/15 11:35
     */
    @GetMapping("/set")
    public String setSession(HttpSession session){
        session.setAttribute("server:port:",port);
        return port;
    }

    /**
     * @Author fyy
     * @Description 共享session取值
     * @Date 2020/5/15 11:37
     */
    @GetMapping("/get")
    public String getSession(HttpSession session){
        return "server:port:"+session.getAttribute("server:port:");
    }

}
